﻿using System.Linq;
using System.Text;
using MRGSP.SurveyMaster.Core;
using MRGSP.SurveyMaster.Core.Model;
using MRGSP.SurveyMaster.Core.Service.Utils;

namespace MRGSP.SurveyMaster.Service.Utils
{
    public class GridRowBuilder : IQuestionBuilder
    {
        public string Build(Question q)
        {
            var b = new StringBuilder();
           
            b.Append(
                string.Format(@"<td><div id='qwrap{0}'>
                        {1}</div></td>", q.Id, HtmlGeneratorFactory.Generate(q)));
            var ch = string.Empty;

            b.Append(q.Children.Aggregate(ch, (current, child) => current + 
                QuestionBuilder.Get(ControlType.GridCell).Build(child)));
            
            return b.ToString();
        }
    }
} 